/*
Code generates Figure 2: descriptives of ex-post and ex-ante choice data and  Table A.11: Testing the Impact of Vignette Salience on Response Patterns
*/


* ex-ante data
*-------------------------------------------------------------------------------

use "$data/initial_data/exante_data", clear 

graph set window fontface "Times New Roman" 

* Figure 2b
*-------------------------------------------------------------------------------

graph bar   chosen_marry, over(bs_inschool_bride) over(bs_age_bride) b1title("Age of Daughter in Described Scenario")  ytitle("Proportion Choosing Marriage" "when Faced with Scenario") asyvar legend(order(1 "Out of school" 2 "Still in school") ring(0)  bplacement(nwest) ) yscale(range(0 1)) ylabel(0(0.2)1) name(b1,replace) scale(1.4) 

graph bar   chosen_marry, over(bs_gov_opt1) over(bs_age_bride)   ytitle("Proportion Choosing Marriage" "when Faced with Scenario") asyvar legend(order(1 "No government job" 2 "Government job") ring(0)  bplacement(nwest)) yscale(range(0 1)) ylabel(0(0.2)1) name(b2, replace) scale(1.4) b1title("Age of Daughter in Described Scenario")

graph combine  b1 b2, ysize(2) xsize(4)

graph export "$output/exante_barchart.png", width(4000) replace

* with confidence intervals
*-------------------------------------------------------------------------------

cibar   chosen_marry, over1(bs_inschool_bride) over2(bs_age_bride) graphopts(b1title("Age of Daughter in Described Scenario")  ytitle("Proportion Choosing Marriage" "when Faced with Scenario")  legend(order(1 "Out of school" 2 "Still in school") ring(0)  bplacement(nwest) ) yscale(range(0 1)) ylabel(0(0.2)1) name(b1,replace) scale(1.4))

cibar   chosen_marry, over1(bs_gov_opt1) over2(bs_age_bride)   graphopts(ytitle("Proportion Choosing Marriage" "when Faced with Scenario")  legend(order(1 "No government job" 2 "Government job") ring(0)  bplacement(nwest)) yscale(range(0 1)) ylabel(0(0.2)1) name(b2, replace) scale(1.4) b1title("Age of Daughter in Described Scenario"))

graph combine  b1 b2, ysize(2) xsize(4)

graph export "$output/exante_barchart_CIs.png", width(4000) replace

* ex-post data
*-------------------------------------------------------------------------------

* load data
use "$data/initial_data/expost_data", clear 
destring _all, replace 

* generate experiment ID
gen double  exper_id=carer_id*100+Bride_Static
keep bsst_* exper_id carer_id
	
* reshape 
reshape long bsst_age_opt bsst_wealth_opt bsst_dowry_opt bsst_schoolgrade_opt bsst_gov_opt bsst_marage_opt bsst_marsch_opt, i(exper_id) j(opt)

gen chosen=(bsst_choice==opt)

* figure in text: 
tab chosen if bsst_marage_opt==13 & bsst_gov_opt==0

* Figure 2a
*-------------------------------------------------------------------------------

graph bar   chosen, over(bsst_gov_opt) over(bsst_marage_opt)  ytitle("Proportion Choosing Option over Alternative") asyvar legend(order(1 "No government job" 2 "Government job") ring(0)  bplacement(nwest)) yscale(range(0 1)) ylabel(0(0.2)1) name(b4, replace) scale(1.4) ysize(2) xsize(2) b1title("Age of Marriage in Described Option")

lab def sch 13 "College"
lab val bsst_marsch_opt sch
graph bar   chosen if bsst_marsch_opt>6,  over(bsst_marsch_opt)  ytitle("Proportion Choosing Option over Alternative")   yscale(range(0 1)) ylabel(0(0.2)1) name(b5,replace) scale(1.4) ysize(2) xsize(2) b1title("Education at Marriage in Described Option")

graph combine  b4 b5, ysize(2) xsize(4)

graph export "$output/expost_barchart.png", width(4000) replace

* with confidence intervals
*-------------------------------------------------------------------------------

cibar    chosen, over1(bsst_gov_opt) over2(bsst_marage_opt)    graphopts(legend(order(1 "No government job" 2 "Government job") ring(0)  bplacement(nwest)) yscale(range(0 1)) ylabel(0(0.2)1) name(b4, replace) scale(1.4) ysize(2) xsize(2) b1title("Age of Marriage in Described Option") ytitle("Proportion Choosing Option over Alternative"))

cibar   chosen if bsst_marsch_opt>6,  over1(bsst_gov_opt) over2(bsst_marsch_opt) graphopts(legend(order(1 "No government job" 2 "Government job") ring(0)  bplacement(nwest)) ytitle("Proportion Choosing Option over Alternative")   yscale(range(0 1)) ylabel(0(0.2)1) name(b5,replace) scale(1.4) ysize(2) xsize(2) b1title("Education at Marriage in Described Option") )

graph combine  b4 b5, ysize(2) xsize(4)
graph export "$output/expost_barchart_CIs.png", width(4000) replace
*/

* Test for salience effects in ex-post data (Table A11)
*-------------------------------------------------------------------------------

* load data
use "$data/initial_data/expost_data", clear 
destring _all, replace 

* generate experiment ID
gen double  exper_id=carer_id*100+Bride_Static
keep bsst_* exper_id carer_id

rename bsst_like_dau salient

* generate choice variable
gen chose_1=bsst_choice==1
lab var chose_1 "Ex Post Choice"

* generate differences between options for all characteristics

* groom/match characteristics
gen d_dowry = bsst_dowry_opt1 - bsst_dowry_opt2
lab var d_dowry "Dowry"

gen d_wealth_1=(bsst_wealth_opt1==1)-(bsst_wealth_opt2==1)
lab var d_wealth_1 "Groom's Wealth = Poor"
gen d_wealth_2=(bsst_wealth_opt1==2)-(bsst_wealth_opt2==2)
lab var d_wealth_2 "Groom's Wealth = Average"
gen d_wealth_3=(bsst_wealth_opt1==3)-(bsst_wealth_opt2==3)
lab var d_wealth_3 "Groom's Wealth = Wealthy"

g d_age = bsst_age_opt1-bsst_age_opt2
lab var d_age "Groom's Age"

g d_schoolgrade = bsst_schoolgrade_opt1-bsst_schoolgrade_opt2
lab var d_schoolgrade "Groom's Education"	

g d_gov = bsst_gov_opt1 - bsst_gov_opt2
lab var d_gov "Government Job"

* age of marriage
foreach i of numlist 14/22 {
	gen d_marage_`i'=(bsst_marage_opt1==`i')-(bsst_marage_opt2==`i')
	lab var d_marage_`i' "Daughter's Age at Marriage=`i'"
	}

* education at marriage
foreach i of numlist   8 9 10 11 12 13 {
	gen d_marsch_`i'=(bsst_marsch_opt1==`i')-(bsst_marsch_opt2==`i')
	lab var d_marsch_`i' "Daughter's Education =`i'"
	}	

* interactions
foreach i of numlist  7 8 9 10 11 12 13 {
	foreach j of numlist 13/22 {
		if `i' <= `j' - 6 {
		gen d_marsch`i'_marage`j'= 0 
		replace d_marsch`i'_marage`j' = (bsst_marsch_opt1==`i' & bsst_marage_opt1==`j')-(bsst_marsch_opt2==`i' & bsst_marage_opt2==`j')
		lab var d_marsch`i'_marage`j' "Ed =`i' & Age = `j'"
		}
	}
}	

* probit regressions of choice on option salience and differences in option characteristics
lab def salient 1 "Salient option"
lab val salient salient

constraint define 1 [chose_1]_cons = 0

probit chose_1 d_marsch*_marage* i.salient, ///
		constraints(1) vce(cluster carer_id)	
estimates store r1		

estadd local age_ed "yes"
estadd local groom_chars "no"
estadd local n_exps=e(N)
estadd local n_indivs=e(N_clust)

margins, dydx(*salient) post
estimates store m1 

probit chose_1 d_marsch*_marage* d_gov d_age d_schoolgrade d_dowry d_wealth* i.salient, ///
		constraints(1) vce(cluster carer_id)
estimates store r2
estadd local age_ed "yes"
estadd local groom_chars "yes"
estadd local n_exps=e(N)
estadd local n_indivs=e(N_clust)

margins, dydx(*salient) post
estimates store m2

esttab r1 m1 r2 m2, keep(1.salient)  noobs b(4) se(4) label star(* 0.10 ** 0.05 *** 0.01) scalars("age_ed  Age x Education Interactions" "groom_chars  Groom/Match characteristics" "n_exps Number of Choice Experiments" "n_indivs Number of Respondents") mtitles("Probit coefs." "Marginal Effects" "Probit coefs." "Marginal Effects")    nodepvars  eqlabels(" " " ")

esttab r1 m1 r2 m2 using "$output/salience_panelA.tex", keep(1.salient)  noobs b(4) se(4) label star(* 0.10 ** 0.05 *** 0.01) scalars("age_ed  Age x Education Interactions" "groom_chars  Groom/Match characteristics" "n_exps Number of Choice Experiments" "n_indivs Number of Respondents") mtitles("Probit coefs." "Marginal Effects" "Probit coefs." "Marginal Effects")    nodepvars  eqlabels(" " " ") booktabs replace




* Test for salience effects in ex-ante data 
*-------------------------------------------------------------------------------

* load data
use "$data/initial_data/exante_data", clear 

replace bs_likeschool= 0 if missing(bs_likeschool)
gen bs_badgirl=1-bs_goodgirl

* label vars
lab def bs_like_daugh 1 "Salient vignette"
lab val bs_like_daugh bs_like_daugh

lab var chosen_marry "."
lab var bs_age_bride "Daughter's Age"
lab var bs_inschool_bride "Currently in School"

lab var bs_likeschool "Daughter Likes School"
lab var bs_badgirl "Daughter has Male Friends"

lab define bs_wealth_opt 1 "Match's Wealth: Very Poor" 2 "Match's Wealth: Average Wealth" 3 "Match's Wealth: Very Wealthy"
lab val bs_wealth_opt bs_wealth_opt

lab var bs_dowry_opt1 "Dowry"
lab var bs_schoolgrade_opt1 "Groom's Education"

lab var bs_gov_opt "Government Job"
lab var bs_age_opt1 "Groom's Age"

gen bs_wealth_opt11 = (bs_wealth_opt1==1)
lab var bs_wealth_opt11 "Groom's Wealth = Poor"
gen bs_wealth_opt13 = (bs_wealth_opt1==3)
lab var bs_wealth_opt13 "Groom's Wealth = Wealthy"


* salience
probit chosen_marry i.bs_like_daugh i.(bs_inschool_bride)##i.bs_age_bride , vce(cluster carer_id) 
estimates store r1		

estadd local age_ed "yes"
estadd local groom_chars "no"
estadd local n_exps=e(N)
estadd local n_indivs=e(N_clust)

margins, dydx(*bs_like_daughter) post
estimates store m1 

probit chosen_marry i.bs_like_daugh i.(bs_inschool_bride)##i.bs_age_bride bs_age_opt1 bs_schoolgrade_opt1 bs_gov_opt1 bs_dowry_opt1 bs_wealth_opt11 bs_wealth_opt13 , vce(cluster carer_id) 
estimates store r2

estadd local age_ed "yes"
estadd local groom_chars "yes"
estadd local n_exps=e(N)
estadd local n_indivs=e(N_clust)

margins, dydx(*bs_like_daughter) post
estimates store m2

esttab r1 m1 r2 m2 , keep(1.bs_like_daughter)  noobs b(4) se(4) label star(* 0.10 ** 0.05 *** 0.01) scalars("age_ed  Age x Education Interactions" "groom_chars  Groom/Match characteristics" "n_exps Number of Choice Experiments" "n_indivs Number of Respondents") mtitles("Probit coefs." "Marginal Effects" "Probit coefs." "Marginal Effects")    nodepvars  eqlabels(" " " ")

esttab r1 m1 r2 m2  using "$output/salience_panelB.tex", keep(1.bs_like_daughter)  noobs b(4) se(4) label star(* 0.10 ** 0.05 *** 0.01) scalars("age_ed  Age x Education Interactions" "groom_chars  Groom/Match characteristics" "n_exps Number of Choice Experiments" "n_indivs Number of Respondents") mtitles("Probit coefs." "Marginal Effects" "Probit coefs." "Marginal Effects")    nodepvars  eqlabels(" " " ") booktabs replace

